<!DOCTYPE HTML>
<html lang="en-US">
<head>
	<meta charset="UTF-8">
	<title>js-object-constructor</title>
</head>
<body>
	
</body>
</html>
<script type="text/javascript">
//这是一个构造函数，首字母大写
function Range(from,to){
	this.from = from;
	this.to = to;
}
//方法
Range.prototype = {
	constructor: Range,
	includes: function(x){
		return this.from <= x && x <= this.to;
	},
	foreach: function(fn){
		for(var x = Math.ceil(this.from); x <= this.to; x++){
			fn(x);
		}
	},
	toString: function(){
		return '(' + this.from + '...' + this.to + ')';
	}
}
//初始化
var r = new Range(1,3);
r.includes(2);	//true;
r.foreach(alert);
console.log(r.toString());
</script>